<template>
  <a-modal :title="title" :destroyOnClose="true" :width="width" :visible="visible" @ok="handleOk" :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" cancelText="关闭">
    <BookCommentForm
      ref="registerForm"
      @ok="submitCallback"
      :formDisabled="disableSubmit"
      :formBpm="false"
      :tableId="props.tableId"
    ></BookCommentForm>
  </a-modal>
</template>

<script lang="ts" setup>

  import { ref, nextTick, defineExpose,defineProps } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import BookCommentForm from './BookCommentForm.vue'
  import { defHttp } from '/@/utils/http/axios';
  import { useListPage } from '/@/hooks/system/useListPage';
  import {getExportUrl, getImportUrl, list} from "@/views/novel/bookComment/BookComment.api";
  import {commentColumns} from "@/views/novel/bookComment/BookComment.data";
  const title = ref<string>('');
  const width = ref<number>(800);
  const visible = ref<boolean>(false);
  const disableSubmit = ref<boolean>(false);
  const registerForm = ref();
  const emit = defineEmits(['register', 'success','tableReload']);
  const dataSource=ref()

  const tableItemData=ref(null)

  const props = defineProps({
    tableId: { default: 0 },
  });

  async function getData(params) {
    const data=await defHttp.get({ url: '/novel/bookComment/detail/list', params });
    console.log(data)
    dataSource.value=data.records
  }

  /**
   *
   * 新增
   */
  function add() {
    title.value = '新增';
    visible.value = true;
    nextTick(() => {
      registerForm.value.add();
    });
  }


  function demoListApi(params){
    params.commentId=tableItemData.value.id
    return defHttp.get({ url: '/novel/bookComment/detail/list', params });
  }

  /**
   * 编辑
   * @param record
   */
  async function edit(record,tableType) {
    title.value =  '回复'
    visible.value = true;
    tableItemData.value=record
    nextTick(() => {
      registerForm.value.edit(record,tableType);
    });
  }

  /**
   * 确定按钮点击事件
   */
  function handleOk() {
    registerForm.value.submitForm();
  }

  /**
   * form保存回调事件
   */
  function submitCallback() {
    handleCancel();
    emit('tableReload')
    emit('success');
  }

  /**
   * 取消按钮回调事件
   */
  function handleCancel() {
    visible.value = false;
  }

  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '编辑',
        onClick: handleEdit.bind(null, record),
      },
    ];
  }

  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    console.log(record)
  }


  defineExpose({
    add,
    edit,
    disableSubmit,
  });
</script>

<style>
  /**隐藏样式-modal确定按钮 */
  .jee-hidden {
    display: none !important;
  }
</style>
